using System;
using System.Collections.Generic;
using System.Text;
using Util;

namespace Crm.Domain.Tests
{
    /// <summary>
    /// Holds a persons name.
    /// </summary>
    /// <remarks>
    /// This is a value object (Evans).
    /// </remarks>
    public sealed class Name
    {
        #region Fields

        private string _firstName;
        private string _lastName;

        #endregion

        #region Constructor

        public Name(string firstName, string lastName)
        {
            # region Preconditions

            ArgumentValidation.ThrowIfNullOrEmpty(firstName, "firstName");
            ArgumentValidation.ThrowIfNullOrEmpty(lastName, "lastName");

            # endregion

            _firstName = firstName;
            _lastName = lastName;
        }
		 
	    #endregion

        #region Fields

        public string FirstName
        {
            get { return _firstName; }
        }

        public string LastName
        {
            get { return _lastName; }
        }

        #endregion

        # region Equality

        /// <summary>
        /// Determines whether the specified object is equal to this object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current object.</param>
        /// <returns><c>true</c> if the specified Object is equal to the current Object; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            #region Preconditions

            if (obj == null)
            {
                return false;
            }

            if (Object.ReferenceEquals(this, obj))
            {
                return true;
            }

            if (this.GetType() != obj.GetType())
            {
                return false;
            } 

            #endregion

            Name toCompareTo = (Name)obj;

            return _firstName == toCompareTo._firstName && _lastName == toCompareTo._lastName;
        }

        /// <summary>
        /// Gets a hash code for the current object.
        /// </summary>
        /// <returns>A hash code for the current object.</returns>
        public override int GetHashCode()
        {
            return (_firstName + _lastName).GetHashCode();
        }

        /// <summary>
        /// Returns a string representation of the name.
        /// </summary>
        public override string ToString()
        {
            return _firstName + " " + _lastName;
        }

        # endregion
    }
}
